"""
@Author : 合肥一元数智教育科技有限公司
@Date :  2025/3/21 10:59
@Description : 
 查询数据
"""
import pymysql

conn = pymysql.connect(
    host='localhost',
    port=3306,
    user='root',
    passwd='root',
    db='python2511',
    charset='utf8'
)

cur = conn.cursor()
# 编写sql
str_sql = "select * from user"
line = cur.execute(str_sql)
print(line)

# fetchall() 获取所有查询结果   结果类型tuple  每条记录tuple  ((),())
"""
rows_data = cur.fetchall()
print(type(rows_data),rows_data)
for row in rows_data:
    print(row)
"""
"""
row_data = cur.fetchone()
print(row_data)
row_data = cur.fetchone()
print(row_data)
row_data = cur.fetchone()
print(row_data)
"""

"""
rows_data = cur.fetchmany(2)
print(rows_data)
rows_data = cur.fetchmany(2)
print(rows_data)
"""

rows_data = cur.fetchmany(4)
print(rows_data)
# 游标的移动 mode='relative'  relative 相对模式
# cur.scroll(1,mode='relative')
# 绝对
cur.scroll(2,mode='absolute')
row_data = cur.fetchone()
print(row_data)

# 释放资源
cur.close()
conn.close()
